Login and get codingSometimes you need to capture stdout in your script. Python makes it easy with
contextlib
'sredirect_stdout
.In this Bite you will use it to get the length of a help text as returned by
help
.Complete
get_len_help_text
which receives a builtin. Runhelp
against this builtin and capture its output in a variable and return its length (number of chars). If a non-builtin is passed into the function, raise aValueError
(hint: you can useBuiltinFunctionType
to check this).Here you see the function in action:
>>> from helplen import get_len_help_text >>> get_len_help_text(max) 402 >>> get_len_help_text(pow) 278 >>> get_len_help_text('bogus') ... ValueErrorGood luck and keep calm and code in Python!
Will you be the 205th person to crack this Bite?
Resolution time: ~22 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 3.43 on a 1-10 difficulty scale.
» You can do it! 😌